package day2;

import day1.Dog;
import day1.Pet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class CollestionTEst2 {
    public static void main(String[] args) {
        List<Pet> list2=new ArrayList<>();//自动推导
        list2.add(new Pet("小花花",100,55));
        list2.add(new Pet("Yellowhuang",66,65));
        list2.add(new Pet("旺财",55,66));
        list2.add(new Pet("哮天犬",44,100));
        list2.add(new Pet("Jiasting",59,33));
        list2.add(new Dog("贾斯汀",100,100,"美利坚流浪狗"));
        System.out.println("初始顺序：");

        for(Pet p:list2)
            System.out.println(p);
        //
        Pet max = Collections.max(list2);
        System.out.println("按照健康值和可爱度，最大的是："+max);
        Pet min = Collections.min(list2);
        System.out.println("按照健康值和可爱度，最小的是："+min);
        System.out.println("按照默认的健康值和可爱度排序：");
        Collections.sort(list2);
        for(Pet p:list2)
            System.out.println(p);
        System.out.println("按照自定义的名字的倒序 排序：");
        Collections.sort(list2,new NameCompartor());
        for(Pet p:list2)
            System.out.println(p);


//        Pet max1 = Collections.max(list2, new NameCompartor());
//        max1.setHealth(4444);
    }
}
//
class NameCompartor implements Comparator<Pet>{

    //按照名字的降序
    @Override
    public int compare(Pet o1, Pet o2) {
        return o1.getName().compareTo(o2.getName());
    }
}